﻿
@{
    ViewBag.Title = "住院登记时查询病人信息";
    Layout = "~/Views/Shared/_Form.cshtml";
    var from = (ViewBag.from as string) ?? "";
}
<style>
    .table-responsive {
        border: 0;
    }

    .ui-jqgrid .ui-jqgrid-pager .ui-pager-table {
        width: 90%;
    }
</style>

<div class="topPanel" style="border-bottom:1px solid rgb(221, 221, 221);margin-bottom: 1%;">
    <div class="search">
        <table class="form">
            <tr>
                <th class="formTitle">病历号：</th>
                <td class="formValue">
                    <input id="txt_blh" name="txt_blh" type="text" class="form-control form-an" placeholder="请输入病历号" />
                </td>
                <th class="formTitle">姓名：</th>
                <td class="formValue">
                    <input id="txt_xm" name="txt_xm" type="text" class="form-control form-an form-an-end" placeholder="请输入姓名或首拼" />
                </td>
                <td style="padding-left: 20px;">
                    <button type="button" id="btn_search" class="btn btn-primary btn-md">&nbsp;查询&nbsp;</button>
                </td>
            </tr>
        </table>
    </div>
</div>
<!--患者信息 包括病历号  姓名 -->
<form id="formPatSer" style="margin:2px;margin-top:10px;">
    <div class="gridPanel">
        <table id="patGridList" rel="formPatSer"></table>
        <div id="gridPager" style="padding-right:20%"></div>
    </div>
</form>

<script>
    //上一个window对象
    var prevWindow;
    if ('@(from)' !== '') {
        prevWindow = top.top.frames['@(from)'];
    }
    else {
        prevWindow = $.currentWindow();
    }

    $(function () {

        var obj = new Object;
        obj.blh = $.request("blh");
        var searInfo = new PatSearchInfo();
        //加载数据
        searInfo.init(obj);

        $('#txt_xm').keyupEnterEvent(function () {
            $('#btn_search').trigger('click');
        });

        //查询
        $("#btn_search").click(function () {
            $("#patGridList").jqGrid('setGridParam', {
                postData: {
                    blh: $("#txt_blh").val(), xm: $("#txt_xm").val()
                },
                page: 1,
                url: "@Url.Action("PatSearchInfo")"
            }).trigger('reloadGrid');
        });
    });
    var PatSearchInfo = (function () {
        //加载列表
        var loadGrid = function (data) {
            var $gridList = $("#patGridList");
            $gridList.dataGrid({
                height: $(window).height() - 200,
                autowidth: false,
                width: $("#formPatSer").width() - 10,
                url: "@Url.Action("PatSearchInfo")",
                postData: { blh: $("#txt_blh").val(), xm: $("#txt_xm").val() },
                caption: '患者信息列表',
                colModel: [
                    { label: '主键', name: 'patid', hidden: true },
                    { label: '病历号', name: 'blh', width: 50, align: 'left' },
                    { label: '姓名', name: 'xm', width: 70, align: 'left' },
                    { label: '出生年月', name: 'csny', hidden: true, width: 120, align: 'left' },
                    {
                        label: '性别', name: 'xb', width: 45, align: 'left', formatter: function (cellvalue) {
                            return $.getGender(cellvalue);
                        }
                    },
                    {
                        label: '年龄', name: 'nlshow', width: 45, align: 'left', formatter: function (cellvalue, options, rowObject) {
                            return getAgeFromBirthTime({ begin: rowObject.csny }).text;
                        }
                    },
                    { label: '证件号', name: 'zjh', width: 150, align: 'left' },
                    { label: '卡号', name: 'kh', width: 80, align: 'left' },
                    { label: '卡类型', name: 'CardTypeName', width: 80, align: 'left' },
                    { label: '病人性质', name: 'brxzmc', width: 60, align: 'left' },
                    { label: 'CardType', name: 'CardType', width: 80, align: 'left', hidden: true, },
                    { label: 'CardId', name: 'CardId', width: 80, align: 'left', hidden: true, },
                     { label: '', name: 'CreateTime', hidden: true }
                ],
                pager: "#gridPager",
                sortname: 'CreateTime desc',
                viewrecords: true
            });
        };

        var myPatSearchInfo = function (data) {

        }

        //加载事件
        myPatSearchInfo.prototype.init = function (data) {
            if (data.blh === "null") {
                $("#txt_blh").val("");
            } else {
                $("#txt_blh").val(data.blh);
            }
            loadGrid(data);
        };
        return myPatSearchInfo;
    }());

    //jqGrid 双击选中某行
    function btn_edit() {
        PatSearchConfirm();
    }

    function PatDbGrid() {
        var $gridList = $("#patGridList");
        var blh = $gridList.jqGridRowValue().blh;
        var obj = new Object();
        obj.blh = blh;
        obj.nlshow = $gridList.jqGridRowValue().nlshow;
        obj.xm = $gridList.jqGridRowValue().xm;
        obj.patid = $gridList.jqGridRowValue().patid;
        obj.startTime = $.currentWindow().$("#ks").val();
        obj.endTime = $.currentWindow().$("#js").val();
        obj.CardId = $gridList.jqGridRowValue().CardId;
        prevWindow.GetQueryFphAjax(obj);
        //关闭窗口
        ReceiptCancle();
    }
    //确定 主页面调用
    function PatSearchConfirm() {
        PatDbGrid();
    }

    //取消
    function ReceiptCancle() {
        $.modalClose();
    }
</script>


